#!/usr/bin/env python
# -*-coding:utf-8 -*-
'''
WHY's first project:
She has learned to control the program flow by loop.
stack and recursion samples will be sorted out
she also need more practise
'''
#[C53(1)]
#a=[1,2,3,4,5]
def SlectionSort(a):
    '''
    SlectionSort: Select minest in the list every time, till the list is sorted by ascend order
    Input unsorted list a
    Return a sorted list
    '''
    for i in range(len(a)):
     m=a[i]
     k=i
     for j in range(i+1,len(a)):
      if a[j]<m:
       m=a[j]
       k=j
     c=a[k]
     a[k]=a[i]
     a[i]=c
    return a

def C52():
    '''
    List every item of the Combinations C52
    '''
    C=[]
    a=[1,2,3,4,5]
    for i in range(5):
     j=a[i]
     B=[]
     B.append(j)
     for m in range(5):
      n=a[m]
      if n not in B:
       B.append(n)
       C.append(B)
       B=[]
       B.append(j) 
      else:
       B=[]
       B.append(j)
    print(C)
    s=[]
    for p in range(len(C)):
     for q in range(p+1,len(C)):
      if SlectionSort(C[q]) == SlectionSort(C[p]):
       s.append(q)
    S=SlectionSort(s)
    for o in range(len(S)-1,-1,-1):
     del(C[S[o]])
    print(SlectionSort(C))

C53()
print ';;;;;;;;;;;;;;;;;\n'
#[C53(2)]
def C53():
    '''
    List every item of the Combinations C53
    '''
    a=[1,2,3,4,5]
    C=[]
    for i in range(5):
     j=a[i]
     B=[]
     B.append(j)
     for m in range(5):
      B=[]
      B.append(j)
      n=a[m]
      if n not in B:
       B.append(n)
       for r in range(5):
        t=a[r]
        if t not in B:
         B.append(t)
         C.append(B)
         B=[]
         B.append(j)
         B.append(n)
        else:
         B=[]
         B.append(j)
         B.append(n)
      else:
       B=[]
       B.append(j)
    D=[C[0]]
    t=C[0]
    for i in range(len(C)):
     if C[i]!= t:
      t=C[i]
      D.append(t)
    print(D)
C532()
print ';;;;;;;;;;;;;;;;;\n'
 
#[merge]
def MergeList(a,b):
    '''
    Merge two sorted list A and B into a sorted list C
    '''
    i=0
    j=0
    c=[]
    while i<len(a) and j<len(b):
     if a[i]>b[j]:
      c.append(b[j])
      j=j+1
     else:
      c.append(a[i])
      i=i+1
    if i<len(a):
     for n in range(1,len(a)+2-i):
      c.append(a[n])
    else:
     for n in range(1,len(b)+2-j):
      c.append(b[n])
    return(c)
a=[1,3,5]
b=[2,4,8,9]
print MergeList(a,b)


